package com.sumer.psychology.tag.domain.model;

import com.sumer.psychology.common.Assert;
import com.sumer.psychology.common.domain.model.IdentifiedValueObject;

import java.io.Serializable;
import java.util.Date;

/**
 * 标签
 * <p/>
 * User: zhenguang.zhu
 * Date: 2014/9/5
 * Time: 9:20
 */
public class Tag extends IdentifiedValueObject implements Serializable {
    private String name;
    private TagType tagType;
    private Date createTime;

    /**
     * 创建标签
     *
     * @param name    name
     * @param tagType tag type
     */
    public Tag(String name, TagType tagType) {
        setName(name);
        setTagType(tagType);
        setCreateTime(new Date());
    }

    public Tag() {
    }

    private void setName(String name) {
        Assert.notEmpty(name, "标签名称不能为空");

        this.name = name;
    }

    private void setTagType(TagType tagType) {
        Assert.notNull(tagType, "标签类型不能为空");

        this.tagType = tagType;
    }

    private void setCreateTime(Date createTime) {
        Assert.notNull(createTime, "创建日期不能为空");

        this.createTime = createTime;
    }

    public String name() {
        return name;
    }

    public TagType tagType() {
        return tagType;
    }

    public Date createTime() {
        return createTime;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Tag tag = (Tag) o;

        if (name != null ? !name.equals(tag.name) : tag.name != null) return false;
        if (tagType != tag.tagType) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + (tagType != null ? tagType.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "Tag{" +
                "name='" + name + '\'' +
                ", tagType=" + tagType +
                ", createTime=" + createTime +
                '}';
    }
}
